﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient; 
using System.Configuration; 

namespace LOGIN
{
    public partial class Code : Form
    {
        public Code()
        {
            InitializeComponent();
        }

        private void Code_Load(object sender, EventArgs e)
        {
            
            TreeNode ManagerNode = new TreeNode(); 
            ManagerNode.Text = "系统管理员";                                   
             this.trv_code.Nodes.Add(ManagerNode);

             TreeNode managerNode = new TreeNode();
             managerNode.Text = "manager";                                
             ManagerNode.Nodes.Add(managerNode);
             TreeNode managerRoleNode = new TreeNode();
             managerRoleNode.Text = "managerRole";                               
             ManagerNode.Nodes.Add(managerRoleNode);

             TreeNode MedicineNode = new TreeNode();
             MedicineNode.Text = "工作人员";                  
             this.trv_code.Nodes.Add(MedicineNode);
            
             TreeNode medicineDataNode = new TreeNode();
             medicineDataNode.Text = "medicineData";                         
             MedicineNode.Nodes.Add(medicineDataNode);
             TreeNode medicineBuyNode = new TreeNode();
             medicineBuyNode.Text = "medicineBuy";                           
             MedicineNode.Nodes.Add(medicineBuyNode);
             TreeNode OutputTableNode = new TreeNode();
             OutputTableNode.Text = "OutputTable";
             MedicineNode.Nodes.Add(OutputTableNode);

                                                 
             TreeNode SupplyerNode = new TreeNode();
             SupplyerNode.Text = "采购人员";                                 
             this.trv_code.Nodes.Add(SupplyerNode);
             TreeNode supplyerNode = new TreeNode();
             supplyerNode.Text = "supplyer";                                  
             SupplyerNode.Nodes.Add(supplyerNode);
             TreeNode ordersNode = new TreeNode();
             ordersNode.Text = "orders";                                  
             SupplyerNode.Nodes.Add(ordersNode);

        }
        private void trv_code_AfterSelect(object sender, TreeViewEventArgs e) 
        {
            if (this.trv_code.SelectedNode.Level == 1)                                         
            {
                SqlConnection sqlConnection = new SqlConnection();
                sqlConnection.ConnectionString =
                    "Server=(local);Database=MyHospital;Integrated Security=sspi";    
                SqlCommand sqlCommand = new SqlCommand();                                               
                sqlCommand.Connection = sqlConnection;                                                   
                ordersHelper.tablename = e.Node.Text.Trim();
                sqlCommand.CommandText = "select * from " + ordersHelper.tablename ;         
                                             
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();                                    
                sqlDataAdapter.SelectCommand = sqlCommand;                                                
                DataTable Table = new DataTable();                                                   
                sqlConnection.Open();                                                                  
                sqlDataAdapter.Fill(Table);                                                        
                sqlConnection.Close();                                                              
                this.dgv_code.DataSource = Table;                                             
                //this.dgv_code.Columns["No"].HeaderText = "学号";                                        
                //this.dgv_code.Columns["Name"].HeaderText = "姓名";
                this.dgv_code.Columns[this.dgv_code.Columns.Count - 1].AutoSizeMode =              
                    DataGridViewAutoSizeColumnMode.Fill;
            }
        }

        private void update_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString =
                "Server=(local);Database=MyHospital;Integrated Security=sspi";              
            SqlCommand sqlCommand = new SqlCommand();                                               
            sqlCommand.Connection = sqlConnection;
            if (ordersHelper.tablename == "manager") 
            {
                sqlCommand.CommandText =                                                                     
                "UPDATE manager"
                + " SET Name=@Name,Gender=@Gender,BirthDate=@BirthDate,ClassNo=@ClassNo,Speciality=@Speciality"
                + " WHERE No=@No;";
                sqlCommand.Parameters.Add("@Name", SqlDbType.VarChar, 0, "Name");          
                sqlCommand.Parameters.Add("@Gender", SqlDbType.Bit, 0, "Gender");
                sqlCommand.Parameters.Add("@BirthDate", SqlDbType.Date, 0, "BirthDate");
                sqlCommand.Parameters.Add("@ClassNo", SqlDbType.Int, 0, "ClassNo");
                sqlCommand.Parameters.Add("@Speciality", SqlDbType.VarChar, 0, "Speciality");
                sqlCommand.Parameters.Add("@No", SqlDbType.Char, 10, "No");
            }
        }

      
    }
}
